/*
 * @lc app=leetcode.cn id=1742 lang=typescript
 *
 * [1742] 盒子中小球的最大数量
 */

// @lc code=start
function countBalls(lowLimit: number, highLimit: number): number {
    const sum = (num: number) => {
        let count = 0;
        while (num) {
            count += num % 10;
            num = Math.floor(num / 10);
        }
        return count;
    };
    const cache = new Map<number, number>();
    for (let i = lowLimit; i <= highLimit; i++) {
        const count = sum(i);
        cache.set(count, (cache.get(count) || 0) + 1);
    }
    return Math.max(...cache.values());
}
// @lc code=end
